﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using BlobTowerDefense.Managers;
using BlobTowerDefense.Tools;

namespace BlobTowerDefense
{
    public static class CursorState
    {
        public static Vector2 Position;
        public static bool IsTowerSelected;
        public static TowerStats TowerSelectedStats;

        public static Microsoft.Xna.Framework.Input.Touch.GestureSample Gesture;

        public static Ray CalculateCursorRay()
        {
            Vector3 nearSource = new Vector3(Position, 0f);
            Vector3 farSource = new Vector3(Position, 1f);

            Vector3 nearPoint = GamePage.Device.Viewport.Unproject(nearSource,
                Camera.ProjectionMatrix, Camera.ViewMatrix, Microsoft.Xna.Framework.Matrix.Identity);

            Vector3 farPoint = GamePage.Device.Viewport.Unproject(farSource,
                Camera.ProjectionMatrix, Camera.ViewMatrix, Microsoft.Xna.Framework.Matrix.Identity);

            Vector3 direction = farPoint - nearPoint;
            direction.Normalize();

            return new Ray(nearPoint, direction);
        }
    }
}
